package com.example.stars_project_android.personalCenter;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ImageButton;
import android.widget.ListView;

import com.example.stars_project_android.R;
import com.example.stars_project_android.adapter.ConcernStarListAdapter;
import com.example.stars_project_android.adapter.MyAdapter;
import com.example.stars_project_android.entity.ConcernStarEnetity;
import com.example.stars_project_android.index.Index;

import java.util.ArrayList;
import java.util.List;

/**
 * 我关注的星界面
 */
public class Concernstar extends AppCompatActivity implements View.OnClickListener {

    private ImageButton imageButton;  //返回按钮
    private List<ConcernStarEnetity> mList = new ArrayList<>();
    private ListView listView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_concernstar);

        setView();

        //设置数据源和数据源
        setData();
        ConcernStarListAdapter adapter = new ConcernStarListAdapter(
                this,
                R.layout.concern_star_item,
                mList
        );
        //ListView绑定适配器
        listView.setAdapter(adapter);
        //ListView item 中的删除按钮的点击事件
        adapter.setOnItemDeleteClickListener(new ConcernStarListAdapter.onItemDeleteListener() {
            @Override
            public void onDeleteClick(int i) {
                mList.remove(i);
                adapter.notifyDataSetChanged();
            }
        });
    }

    private void setView() {
        listView = findViewById(R.id.lv_concern_star);
        imageButton = findViewById(R.id.ib_concern_star_return);
        imageButton.setOnClickListener(this);
    }

    private void setData() {
        mList = new ArrayList<>();
        ConcernStarEnetity concernStarEnetity = new ConcernStarEnetity(R.mipmap.star,"BDL 4726-134-1","取消关注");
        mList.add(concernStarEnetity);
        ConcernStarEnetity concernStarEnetity1 = new ConcernStarEnetity(R.mipmap.star,"HDK 4326-131-4","取消关注");
        mList.add(concernStarEnetity1);
        ConcernStarEnetity concernStarEnetity2 = new ConcernStarEnetity(R.mipmap.star,"LSM J2043-5610","取消关注");
        mList.add(concernStarEnetity2);
        ConcernStarEnetity concernStarEnetity3 = new ConcernStarEnetity(R.mipmap.star,"BD+36 238","取消关注");
        mList.add(concernStarEnetity3);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.ib_concern_star_return:
                //返回到个人中心页面
                Intent intent = new Intent(this, Index.class);
                intent.putExtra("index",4);
                startActivity(intent);
                break;
            default:
                break;
        }
    }

}